package realQuestion.didi;

import binaryTree.basic.TreeNode;

public class Class98 {

    long pre=Long.MIN_VALUE;
    public boolean isValidBST(TreeNode root) {
        if (root==null){
            return   true;
        }
        if (!isValidBST(root.left)){
            return  false;
        }
        if (root.val<pre){
            return false;
        }
        pre=root.val;
        if (!isValidBST(root.right)){
            return  false;
        }
      return  true;
    }

    public static void main(String[] args) {
        TreeNode treeNode1 = new TreeNode(1);
        TreeNode treeNode2 = new TreeNode(2);
        TreeNode treeNode3 = new TreeNode(3);
        treeNode2.left=treeNode1;
        treeNode2.right=treeNode3;
        Class98 class98 = new Class98();
        System.out.println(class98.isValidBST(treeNode2));


    }

}
